package cn.drew.house.service.impl;

import cn.drew.basic.utils.PageList;
import cn.drew.house.domain.HousingInformation;
import cn.drew.house.mapper.HousingInformationMapper;
import cn.drew.house.query.HousingInformationQuery;
import cn.drew.house.service.HousingInformationService;
import cn.drew.org.domain.Employee;
import cn.drew.org.mapper.EmployeeMapper;
import cn.drew.org.query.EmployeeQuery;
import cn.drew.org.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class HousingInformationServiceImpl implements HousingInformationService {

    @Autowired
    private HousingInformationMapper housingInformationMapper;
    @Override
    public void add(HousingInformation housingInformation) {
        housingInformationMapper.add(housingInformation);
    }

    @Override
    public void update(HousingInformation housingInformation) {
        housingInformationMapper.update(housingInformation);
    }

    @Override
    public void delete(Long id) {
        HousingInformation id1 = housingInformationMapper.findById(id);
        if (id1.getHstatus() == 2){
            housingInformationMapper.delete(id);
        }

    }

    @Override
    public HousingInformation findById(Long id) {
        return housingInformationMapper.findById(id);
    }

    @Override
    public List<HousingInformation> findAll() {
        return housingInformationMapper.findAll();
    }



    @Override
    public PageList<HousingInformation> queryByPage(HousingInformationQuery housingInformationQuery) {
        Integer count = housingInformationMapper.queryByCount(housingInformationQuery);
        if (count == 0 || count == null){
            return new PageList(0,new ArrayList());
        }else{
            List<HousingInformation> housingInformations = housingInformationMapper.queryByPage(housingInformationQuery);
            return new PageList<HousingInformation>(count,housingInformations);
        }

    }

    @Override
    public void patchDelete(List<Long> ids) {
        housingInformationMapper.patchDelete(ids);
    }

//    @Override
//    public List<Employee> findByDeptid(Long deptid) {
//        List<Employee> employees = housingInformationMapper.findAll();
//        System.out.println(deptid);
//        //将departmentId 和deptid 相等的数据过滤 ,再转化为list
//        return employees.stream().filter(emp -> deptid.equals(emp.getDepartmentId())).collect(Collectors.toList());
//
//    }
}
